package com._58city.spark.app.dao;

import java.util.Map;

import org.apache.commons.lang3.StringUtils;

import com._58city.spark.app.DaoUtil;

/**
 * @author lihao 根据流量日志，转化的Dto对象
 */
public class TrackDto implements BaseDto {

	public static final String NULL = "null";

	public static final String PAGE_TYPE_LIST = "list";

	public static final String PAGE_TYPE_DETAIL = "detail";

	public final static char SPLIT = 1;

	private String cookie;

	private Map<String, String> trackURL;

	private String pageType;

	private String catePath;

	private long lastCateId;

	// private String platform;//-1 pc 0 mobile 1 wap 2 app

	private String busiLine; // 业务线

	private int platform;

	private String url;

	protected long formaterTime; // 根据时间间隔格式化的时间点。

	private String machineRoom;// 新旧机房

	public String getMachineRoom() {
		return machineRoom;
	}

	public void setMachineRoom(String machineRoom) {
		this.machineRoom = machineRoom;
	}

	public TrackDto() {
		super();
	}

	public TrackDto(String cookie, String pageType, String catePath) {
		super();
		this.cookie = cookie;
		this.pageType = pageType;
		this.catePath = catePath;
		if (StringUtils.isNotBlank(catePath)) {
			this.lastCateId = Long.valueOf(catePath.substring(catePath.lastIndexOf(",") + 1));
		} else {
			this.lastCateId = -1;
		}
	}

	public TrackDto(String cookie) {
		super();
		this.cookie = cookie;
		this.lastCateId = -1;
	}

	public TrackDto(String cookie, String pageType) {
		super();
		this.cookie = cookie;
		this.pageType = pageType;
		this.lastCateId = -1;
	}

	public long getLastCateId() {
		return lastCateId;
	}

	public void setLastCateId(long lastCateId) {
		this.lastCateId = lastCateId;
	}

	public String getCookie() {
		return cookie;
	}

	public void setCookie(String cookie) {
		this.cookie = cookie;
	}

	public String getPageType() {
		return pageType;
	}

	public void setPageType(String pageType) {
		this.pageType = pageType;
	}

	public String getCatePath() {
		return catePath;
	}

	public Map<String, String> getTrackURL() {
		return trackURL;
	}

	public void setTrackURL(Map<String, String> trackURL) {
		this.trackURL = trackURL;
	}

	public void setCatePath(String catePath) {
		this.catePath = catePath;
	}

	public String getBusiLine() {
		return busiLine;
	}

	public void setBusiLine(String busiLine) {
		this.busiLine = busiLine;
	}

	public String getUrl() {
		return url;
	}

	public void setUrl(String url) {
		this.url = url;
	}

	

	@Override
	public String toString() {
		return "TrackDto [" + (cookie != null ? "cookie=" + cookie + ", " : "")
				+ (trackURL != null ? "trackURL=" + trackURL + ", " : "")
				+ (pageType != null ? "pageType=" + pageType + ", " : "")
				+ (catePath != null ? "catePath=" + catePath + ", " : "") + "lastCateId=" + lastCateId + ", "
				+ (busiLine != null ? "busiLine=" + busiLine + ", " : "") + "platform=" + platform + ", "
				+ (url != null ? "url=" + url + ", " : "") + "formaterTime=" + formaterTime + "]";
	}

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub

		String s = "75689f4ff16803a6a741a0d0669fa3503079756124979827.156.18.1072,7_allv1.0.114338430941524,293328{\"idfa\":\"AC56C0DF-14F3-4281-8FB1-7D71CE07DCE8\"}--{\"request\":\"http://i.webapp.58.com/zjk/ershouche/22152179737635x.shtml?formatsource=detail_currentcate&operate=isfilter&fromdc=mdozs&fromdl=fz&topcate=car&utps=1433063902000&os=ios&webaddress=0x1fc42e10\",\"cate\":\"4,29\",\"area\":\"3328\",\"actiontype\":\"show\",\"pagetype\":\"detail\",\"params\":[]}-{\"operate\":\"first\",\"source\":\"ordinarycate\"}71CC0546-3118-4253-982C-667A951906DA75689f4ff16803a6a741a0d0669fa350380000iPhone4S_iOS6.1.25.0.4iphone6.1.2WIFI2015060917445225.739111119.356888福州-福清-音西320_460-";

		TrackDto dto = DaoUtil.track_app(s);
		System.out.println(dto.toString());

		// String s=
		// "05cDE1VKy/qwcRhPBmweAg== 1430965398.316 218.11.218.10 - - [07/May/2015:10:23:18 +0800] GET /m/empty.js.gif?site_name=M58&tag=pvstatall&referrer=http%3A%2F%2Fqy.m.58.com%2Fm_detail%2F29625853099532%2F%3FPGTID%3D14309653392700.8543174348305911%26ClickID%3D2&type=my&post_count=-1&_trackParams=NA&window_size=320x372&_ga_utma=75252886.915698242.1430965399.1430965399.1430965399.1&utm_source=enwang&trackURL={'new_uv':'1','new_session':'0','init_refer':'http%3A%2F%2Fwww.baidu.com%2Ffrom%3D844b%2Fs%3Fword%3D58%25E5%2590%258C%25E5%259F%258E%25E7%25BD%2591%25E6%258B%259B%25E8%2581%2598%26ts%3D5236192%26t_kt%3D167%26sa%3Dis_2%26ms%3D1%26ss%3D100%26rq%3D58','spm':'','utm_campaign':'','utm_source':'enwang','GTID':'14309653989580.9273508286569268'}&rand_id=0.9536163078155369 HTTP/1.1 \"200\" 35 \"http://jianli.m.58.com/login/?type=0&infoid=21142547040267&itype=0&areaid=751&dispname=xt&path=http://qy.m.58.com/m_detail/29625853099532/?PGTID=14309653392700.8543174348305911&ClickID=2&list=http://m.58.com/xt/zplvyoujiudian/21142547040267x.shtml?type=0\" \"Mozilla/5.0 (iPhone; CPU iPhone OS 8_1_3 like Mac OS X) AppleWebKit/600.1.4 (KHTML, like Gecko) Version/8.0 Mobile/12B466 Safari/600.1.4\" \"-\" 0.014 - | -";

		// String s
		// ="05dzXVSdFDaH1DjXIcNXAg== 1429526523.603 183.228.255.70 - - [20/Apr/2015:18:42:03 +0800] GET /pc/empty.js.gif?fromid=referrer4&site_name=58&tag=pvstatall&referrer=http%3A%2F%2Fapi.vip.58.com%2Fbinding%2Fweixin&type=my&post_count=-1&_trackParams=NA&window_size=815x800&_ga_utma=253535702.256524881.1419580471.1429526461.1429526499.5&trackURL={'new_uv':'3','new_session':'0','init_refer':'http%3A%2F%2Fhao.360.cn%2F','GTID':'14295265221160.3065101446118206','cate':'','area':'','pagetype':'my','page':'safesetwxcg','GA_pageview':''}&rand_id=0.9171668097842485 HTTP/1.1 \"200\" 35 \"http://api.vip.58.com/binding/weixin\" \"Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/31.0.1650.63 Safari/537.36\" \"-\" 0.000 - | 30739107818762";
		// String s
		// ="05dzXFT2in2Y2yKECgJ0Ag== 1429526523.606 113.87.63.191 - - [20/Apr/2015:18:42:03 +0800] GET /pc/empty.js.gif?fromid=referrer4&site_name=58&tag=pvstatall&referrer=http%3A%2F%2Fsz.58.com%2Fshiyansz%2Fcangku%2F%3Futm_source%3Dd_hao360%26spm%3D360-mingzhan-1010%26PGTID%3D14295263831370.8151282512117177%26ClickID%3D1&type=detail&post_count=-1&_trackParams=5353%3A1%40%405354%3A%E9%9D%A2%E8%AE%AE%40%405356%3A1%40%405357%3A5%40%405360%3A530687556%40qq.com%40%405362%3A14045507791104%40%405363%3A249%40%405754%3A1476%40%405935%3A%E9%9D%A2%E8%AE%AE%40%406646%3A100%40%406693%3A1*8*2%40%407510%3A485488%40%407515%3A80%40%407576%3A92%40%407660%3A14045507791104%40%408661%3A1%40%409011%3A15431612545031%40%409047%3A1%40%409679%3A%E9%9D%A2%E8%AE%AE%40%409680%3A%E9%9D%A2%E8%AE%AE%40%4010241%3A1%40%4010243%3A1%40%4010374%3A0%40%405332%3A%E4%BB%93%E7%AE%A1%E5%91%98%40%405333%3A%E5%88%98%E5%B0%8F%E5%A7%90%40%406691%3A22.685356%40%406692%3A113.94447%40%408431%3A0%40%409278%3A05dzXFUJGqi%2BUD4qC9R9Ag%40%4010589%3A00000000%40%408992%3A00000000%40%409184%3A2015-08-16%2009%3A11%3A11%40%405358%3A0%40%409773%3A20150420132406%40%409382%3A11%3A1%40%407109%3A113.93790300670001%40%407110%3A22.679696016399998%40%405923%3A482851446%40%406838%3A21650773983265&userid=15431612545031&loadtime=282&window_size=1581x752&_ga_utma=253535702.655446202.1425443679.1429526373.1429526377.26&trackURL={'new_uv':'14','new_session':'0','init_refer':'http%3A%2F%2Fhao.360.cn%2F','GTID':'14295265485730.09015124989673495','GA_pageview':'/sz/job/zpwuliucangchu/detail/','cate':'9224,13913,10437','localarea':'4,1812,6156','loginuid':'0','area':'4,1812,6156','is_biz':'false','pagetype':'detail','is_full':'1','is_qiuzhi':'0','thirdcate':'%E4%BB%93%E5%BA%93%E7%AE%A1%E7%90%86%E5%91%98','source':'0','is_zhijie':'0','shopid':'15431612545031','companyid':'14045507791104','userid':'15431612545031','itemid':'21650773983265','localcate':'574,593,2406'}&rand_id=0.25039864936843514 HTTP/1.1 \"200\" 35 \"http://sz.58.com/zpwuliucangchu/21650773983265x.shtml?utm_source=d_hao360&spm=360-mingzhan-1010&PGTID=14295263854530.9425879043992609&ClickID=13\" \"Mozilla/5.0 (Windows NT 5.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/30.0.1599.101 Safari/537.36\" \"-\" 0.021 - | -";
		// String s
		// ="05dzYlULsdEegWzpDY7fAg== 1429582785.460 120.36.175.197 - - [21/Apr/2015:10:19:45 +0800] GET /pc/empty.js.gif?fromid=referrer4&site_name=58&tag=pvstatall&referrer=http%3A%2F%2Fmy.58.com%2F%3Fpts%3D1429582778913&type=vip&post_count=-1&_trackParams=NA&window_size=1903x851&_ga_utma=253535702.1575040351.1429262491.1429509041.1429582803.5&trackURL={'new_uv':'10','new_session':'0','init_refer':'http%3A%2F%2Fwww.haosou.com%2Fs%3Fie%3Dutf-8%26src%3Dse7_toolbar%26q%3D58','GTID':'14295828159600.6098394047003239','is_biz':'true','pagetype':'vip','page':'pro_zp_home'}&rand_id=0.5028313987422734 HTTP/1.1 \"200\" 35 \"http://vip.58.com/index/zp/?r=0.22564216606174936\" \"Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/31.0.1650.63 Safari/537.36\" \"-\" 0.000 - | 29211362395656";
		// String s
		// ="05dzYlULsdEegWzpDY7fAg== 1429582785.460 120.36.175.197 - - [21/Apr/2015:10:19:45 +0800] GET /pc/empty.js.gif?fromid=referrer4&site_name=58&tag=pvstatall&referrer=http%3A%2F%2Fmy.58.com%2F%3Fpts%3D1429582778913&type=vip&post_count=-1&_trackParams=NA&window_size=1903x851&_ga_utma=253535702.1575040351.1429262491.1429509041.1429582803.5&trackURL={'new_uv':'10','new_session':'0','init_refer':'http%3A%2F%2Fwww.haosou.com%2Fs%3Fie%3Dutf-8%26src%3Dse7_toolbar%26q%3D58','GTID':'14295828159600.6098394047003239','is_biz':'true','page':'pro_zp_home'}&rand_id=0.5028313987422734 HTTP/1.1 \"200\" 35 \"http://vip.58.com/index/zp/?r=0.22564216606174936\" \"Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/31.0.1650.63 Safari/537.36\" \"-\" 0.000 - | 29211362395656";
		// String s =
		// "05cDE1VRrIBRZ74MBTXKAg== 1432800907.598 222.170.84.222 - - [28/May/2015:16:15:07 +0800] GET /m/empty.js.gif?site_name=M58&tag=pvstatall&referrer=http%3A%2F%2Fm.58.com%2Fdq%2F%3Futm_source%3Dxiaomi_gg&type=list&post_count=611&_trackParams=NA&smsc=0ab2e8dd936f99800ca3584af79e54f6daaf95c2b093fe6ea2b60ed8b72f783a7c65bcbf39d54fbc95039b2ad726dd0c923933553f0330a6f4e42d5c60c8e02195bbec835403bf7889d12d5463e76637dd7d15e89443dc65db0339714a68fb7b5859f94fdfae08aef3dee9a6597fe4a4d6094f9a3142f6cab2285a76499efbd290a63a30c2d20eebe15293ed1552746ca5207f726bbcdfe98c35f7d7806b4a50bf09a3c48e5f3eed1460801007985256e2fb990a7a15594b67fa15056229743fdb389051ebdfd61b08c4f9de88eea0c00c8d23faeee1c0f1b7a2e8f713e36131&loadtime=1792&window_size=360x514&_ga_utma=253535702.1045289012.1431415941.1431415941.1432606284.2&utm_source=xiaomi_gg&trackURL={%27new_uv%27:%274%27,%27new_session%27:%270%27,%27init_refer%27:%27%27,%27spm%27:%27%27,%27utm_campaign%27:%27%27,%27utm_source%27:%27xiaomi_gg%27,%27GTID%27:%2714328009023510.004783695563673973%27,%27addtional_count%27:%270%27,%27actiontype%27:%27m_zhuzhan%27,%27pagesize%27:%2725%27,%27area%27:%27375%27,%27cate%27:%279224,13928%27,%27promationinfo_count%27:%2747%27,%27adinfo_count%27:%270%27,%27pagenum%27:%271%27,%27pagetype%27:%27list%27,%27commoninfo_count%27:%270%27,%27topinfo_count%27:%270%27,%27is_biz%27:%27false%27,%27GA_pageview%27:%27/m/dq/job/siji/list/%27}&EventTag=loadMorePage&pagenum=2&rand_id=0.15272709843702614 HTTP/1.1 \"200\" 35 \"http://m.58.com/dq/siji/?from=home_job_5&PGTID=14328008320600.47257322119548917&ClickID=1\" \"Mozilla/5.0 (Linux; U; Android 4.4.4; zh-cn; 2014812 Build/KTU84P) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Mobile Safari/537.36 XiaoMi/MiuiBrowser/2.0.1\" \"-\" 0.001 - | -";
		// String s =
		// "05dvOVKhkNCKbUJWM5W3Ag== 1432802144.969 113.7.114.216 - - [28/May/2015:16:35:44 +0800] GET /m/empty.js.gif?site_name=M58&tag=pvstatall&referrer=http%3A%2F%2Fm.58.com%2Fmdj%2Fyewu%2F21230313975319x.shtml%3Futm_source%3Dbaiduhezuo%26cate%3Djob%26city%3Dmdj%26rootCate%3Djob&type=temPage&post_count=-1&_trackParams=NA&window_size=320x359&_ga_utma=253535702.31311187.1386320088.1432793124.1432793547.25&utm_source=baiduhezuo&trackURL={'new_uv':'46','new_session':'0','init_refer':'http%3A%2F%2Fsportsapi.baidu.com%2Fmiddle%3Fmod%3Dzhaopin%26lcid%3Dweizhan%26srcid%3D3133%26encrypt%3D1%26setype%3D1%26rn%3D10%26pn%3D0%26query%3D%25E7%2589%25A1%25E4%25B8%25B9%25E6%25B1%259F%257C58%257C%25E5%2590%258C%25E5%259F%258E%257C%25E6%258B%259B%25E8%2581%2598%257C%25E4%25BF%25A1%25E6%2581%25AF%257C%26province%3D%25E9%25BB%2591%25E9%25BE%2599%25E6%25B1%259F%26city%3D%25E7%2589%25A1%25E4%25B8%25B9%25E6%25B1%259F%26bd_from_id%3Dwise%26bd_ref_id%3Dbaiduboxapp%26bd_channel_id%3Dlight_null%26bd_sub_page%3Dwz_zhaopin%26bd_source_light%3D3056366','spm':'','utm_campaign':'','utm_source':'baiduhezuo','GTID':'14328021446370.9683687107171863','cate':'0','area':'0','pagetype':'detail','actiontype':'bangbang','source':'0','is_biz':'false','GA_pageview':'/m/bangbang/contact/detail/'}&rand_id=0.6394059855956584 HTTP/1.1 \"200\" 35 \"http://m.58.com/bangbang/contact/?uid=4153441774598\" \"Mozilla/5.0 (iPhone; CPU iPhone OS 6_1_2 like Mac OS X) AppleWebKit/536.26 (KHTML, like Gecko) Mobile/10B146 rabbit%2F1.0 baiduboxapp/0_0.0.5.6_enohpi_069_046/2.1.6_1C2%254enohPi/1099a/6ADA2D8A10DC879CDF75D31C03B1448532013DBACONKCCCFGAP/1\" \"-\" 0.004 - | -";
		// String s =
		// "05cDFFVlZ3GWKBSeCzWfAg== 1432802792.291 124.119.61.130 - - [28/May/2015:16:46:32 +0800] GET /m/empty.js.gif?site_name=M58&tag=pvstatall&referrer=http%3A%2F%2Fm.58.com%2Fshz%2Fzufang%2F21591356140810x.shtml%3FPGTID%3D14328026007740.49436287791468203%26ClickID%3D9&type=temPage&post_count=-1&_trackParams=NA&window_size=360x488&utm_source=532&trackURL={%27new_uv%27:%274%27,%27new_session%27:%270%27,%27init_refer%27:%27http%3A%2F%2Fm.baidu.com%2Ffrom%3D1011384e%2Fs%3Fword%3D58%26ts%3D1830919%26t_kt%3D494%26sa%3Dihr_1%26ss%3D001%27,%27spm%27:%27%27,%27utm_campaign%27:%27%27,%27utm_source%27:%27532%27,%27GTID%27:%2714328028057470.21425291476771235%27,%27cate%27:%270%27,%27area%27:%270%27,%27pagetype%27:%27detail%27,%27actiontype%27:%27bangbang%27,%27source%27:%270%27,%27is_biz%27:%27false%27,%27GA_pageview%27:%27/m/bangbang/contact/detail/%27}&rand_id=0.1733599565923214 HTTP/1.1 \"200\" 35 \"http://m.58.com/bangbang/contact/?uid=10015117571335\" \"Mozilla/5.0 (Linux; Android 4.4.2; vivo X5L Build/KOT49H) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/33.0.0.0 Mobile Safari/537.36\" \"-\" 0.001 - | -";
		// String s =
		// "05dz8VUwCE9AKAuODISYAg== 1432804777.428 183.206.174.119 - - [28/May/2015:17:19:37 +0800] GET /m/empty.js.gif?site_name=M58&tag=pvstatall&referrer=&type=detail&post_count=-1&_trackParams=&userid=54803066&loadtime=472&window_size=320x494&_ga_utma=253535702.1121211390.1429307594.1429307594.1429325606.2&utm_source=link&trackURL={'new_uv':'6','new_session':'0','init_refer':'','spm':'b-26581433340935-ms-f-sq.zhaopin','utm_campaign':'','utm_source':'link','GTID':'14328047260970.9768489561975002','cate':'9224,13928','area':'172,2965,11871','pagetype':'detail','source':'6','userid':'54803066','actiontype':'qqclient','is_biz':'false','GA_pageview':'/m/SQ/nj/job/siji/detail/'}&rand_id=0.07083472236990929 HTTP/1.1 \"200\" 35 \"http://m.58.com/nj/siji/22111741944587x.shtml?-15=13&adtype=3\" \"Mozilla/5.0 (Linux; U; Android 4.2.2; zh-cn; V182 Build/JDQ39) AppleWebKit/533.1 (KHTML, like Gecko)Version/4.0 MQQBrowser/5.4 TBS/025413 Mobile Safari/533.1 V1_AND_SQ_5.5.1_236_YYB_D QQ/5.5.1.2435 NetType/WIFI WebP/0.3.0\" \"-\" 0.000 - | 30706537866251";

		// TrackToObjectFormat track = new TrackToObjectFormat();
		// TrackInfo trackInfo = track.getTrackInfo(s);
		// System.out.println(trackInfo.getTkPageType() + " "+
		// trackInfo.getTkCookieID());
		// System.out.println(trackInfo.getTkTrackURL());
		// System.out.println(trackInfo.getTkUrl());
		// TrackDto dto2 = DaoUtil.track(s);

		// System.out.println(dto2.getPageType());
		// System.out.println(dto2.getUrl());

		// long vpPv = 0;
		// if(dto.getPageType().contains(TrackDto.PAGE_TYPE_LIST)) vpPv++;
		// System.out.println(vpPv);

		// if (s.indexOf("tag=pvstatall") > 0) {
		// String pattern =
		// "([\\d\\w=]*) .*,'cate':'([\\d,]*)',.*,'pagetype':'([\\w]*)',.*";
		// Pattern r = Pattern.compile(pattern);
		// Matcher m = r.matcher(s);
		// if (m.find()) {
		// int count = m.groupCount();
		// for(int i=1;i<=count;i++){
		// System.out.println("Found value: " + m.group(i) );
		// }
		// } else {
		// pattern = "([\\d\\w=]*) .*,'pagetype':'([\\w]*)',.*";
		// r = Pattern.compile(pattern);
		// m = r.matcher(s);
		// if (m.find()) {
		// int count = m.groupCount();
		// for(int i=1;i<=count;i++){
		// System.out.println("Found value: " + m.group(i) );
		// }
		// }else{
		// pattern = "([\\d\\w=]*) .*";
		// r = Pattern.compile(pattern);
		// m = r.matcher(s);
		// if (m.find()) {
		// int count = m.groupCount();
		// for(int i=1;i<=count;i++){
		// System.out.println("Found value: " + m.group(i) );
		// }
		// }else
		// System.out.println("NO MATCH");
		// }
		// }
		//
		// }

	}

	public long getFormaterTime() {
		return formaterTime;
	}

	public void setFormaterTime(long formaterTime) {
		this.formaterTime = formaterTime;
	}

	public int getPlatform() {
		return platform;
	}

	public void setPlatform(int platform) {
		this.platform = platform;
	}

}
